﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Model;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.DAL
{
    /// <summary>
    /// The repository for hospital patients data manipulation.
    /// </summary>
    public class HospitalPatientsRepository : BaseRepository<HospitalPatient>, IHospitalPatientsRepository
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="HospitalPatientsRepository"/> class.
        /// </summary>
        /// <param name="dataServiceContext">The data service context.</param>
        public HospitalPatientsRepository(IDataServiceContext<HospitalPatient> dataServiceContext)
            :base(dataServiceContext)
        {

        }

        /// <summary>
        /// Deletes the user as patient.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        public void DeleteUserAsPatient(string userID)
        {
            var patient = GetHospitalPatientByUser(userID);

            if(patient != null) Delete(patient);
        }

        /// <summary>
        /// Gets the hospital patient by user.
        /// </summary>
        /// <param name="userID">The user ID.</param>
        /// <returns></returns>
        public HospitalPatient GetHospitalPatientByUser(string userID)
        {
            return Entities.Where(p => p.Patient == userID).FirstOrDefault();
        }
    }
}
